package com.cxm.homework8.jdbcTmp.update;

import org.springframework.jdbc.core.JdbcTemplate;

public class UserDaoImpl implements UserDao {
    JdbcTemplate jdbcTemplate;
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
    }
    @Override
    public boolean reg(User user) {
        String sql="insert into user(username,password,balance) value(?,?,?);";
        Object[] pram = new Object[]{user.getUsername(),user.getPassword(),user.getBalance()};
        int rows = jdbcTemplate.update(sql, pram);
        if (rows>0)return true;
        else return false;
    }

    @Override
    public boolean del(int id) {
        String sql ="delete from user where id=?";
        Object[] pram = new Object[]{id};
        int rows = jdbcTemplate.update(sql, pram);
        if (rows>0)return true;
        else return false;
    }
}
